<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>打苹果</title>
		<style type="text/css">
			#main {
				width: 800px;
				height: 600px;
				background-image: url(img/背景.png);
				margin: auto;
			}
			
			#div1 {
				position: absolute;
				top: 200px;
				left: 600px;
				display: none;
			}
			
			#kaishi {
				cursor: pointer;
				position: relative;
				left: 43px;
				top: 46px;
				opacity: 0.3;
				outline: none;
				height: 50px;
				width: 50px;
				border-radius: 50px 50px 50px 50px;
			}
			
			#zhanting {
				cursor: pointer;
				position: relative;
				left: 15px;
				top: 25px;
				opacity: 0.3;
				outline: none;
				height: 43px;
				width: 43px;
				border-radius: 50px 50px 50px 50px;
			}
			
			#jieshu {
				cursor: pointer;
				position: relative;
				left: 112px;
				top: -5px;
				opacity: 0.3;
				outline: none;
				height: 45px;
				width: 45px;
				border-radius: 50px 50px 50px 50px;
			}
			
			#shezhi {
				cursor: pointer;
				position: relative;
				left: 150px;
				top: 62px;
				opacity: 0.3;
				outline: none;
				height: 40px;
				width: 40px;
				border-radius: 50px 50px 50px 50px;
			}
			
			#top1 div {
				position: absolute;
				width: 63px;
				height: 71px;
				line-height: 71px;
				color: white;
				font-size: 40px;
				text-align: center;
				background-image: url(img/苹果.png);
			}
			
			#top1 {
				position: relative;
				height: 475px;
			}
			
			#top1 .psPg {
				width: 138px;
				height: 76px;
				background-image: url(img/破裂苹果.png);
			}
			
			#lanzi {
				border: 1px solid;
				width: 180px;
				height: 135px;
				position: relative;
				top: -70px;
				left: 590px;
				background-image: url(img/篮子.png);
			}
			#jishu{
				border: 1px solid;
				width: 110px;
				height: 80px;
				margin: auto;
				margin-top: 10px;
				border-radius:40px ;
			}
			#jishu img{
				width: 30px;
			}
		</style>
		<script type="text/javascript">
			function jianpan(e) {
				var key = e.keyCode;
				var top1 = document.getElementById("top1");
				for (var i = 0; i < top1.children.length; i++) {
					var code = top1.children[i].getAttribute("keycode");
					if (key == code) {
						top1.removeChild(top1.children[i])
						break;
					}
				}
			}
			var creatInterval = 0;
			var moveInterval = 0;
			var stop;

			function kaishi() {
				if (creatInterval == "0" && moveInterval == "0") {
					creatInterval = setInterval("creatPg()", 1000);
					moveInterval = setInterval("movePg()", 100);
				}
				//间隔时间创建苹果
				//每个苹果50毫秒向下移动var i=5;
				//				i=5;
				//				var div1 = document.getElementById("div1")
				//				div1.style.display = "block";
				//				var i = 5;
				//				stop = setInterval(function() {
				//					i--;
				//					div1.innerHTML = "游戏将要开始:"+i ;
				//					if (i == 0) {
				//						div1.style.display = "none"
				//						
				//					}
				//				}, 1000)
			}

			function jieshu() {
				clearInterval(creatInterval);
				clearInterval(moveInterval);
				top1.innerHTML = null;
			}

			function zanTing() {
				clearInterval(creatInterval);
				clearInterval(moveInterval);
				creatInterval = 0;
				moveInterval = 0;
			}

			function creatPg() {
				var div = document.createElement("div");
				var num = parseInt(Math.random() * 26) + 65;
				div.innerHTML = "&#" + num + ";";
				div.setAttribute("keycode", num);
				var left = parseInt(Math.random() * 700) + 10;
				div.style.left = left + "px";
				div.style.top = "0px";
				document.getElementById("top1").appendChild(div);
			}

			function movePg() {
				var top1 = document.getElementById("top1");
				for (var i = 0; i < top1.children.length; i++) {
					var t = parseInt(top1.children[i].style.top);
					t += 10;
					top1.children[i].style.top = t + "px";
					if (t >= 370) {
						top1.children[i].className = "psPg";
						top1.children[i].innerHTML = "";
					}
					if (t > 400) {
						top1.removeChild(top1.children[i])
					}
				}
			}
		</script>
	</head>

	<body onkeydown="jianpan(event)">
		<div id="main">
			<div id="div1">
				游戏将要开始:5S
				<img style="width: 150px;  border-radius:150px " src="img/aec379310a55b319be8e12a342a98226cefc17f4.gif"/>
			</div>
			<div id="top1">
				<!--<div id="">
					A
				</div>-->

			</div>
			<div id="top2">
				<input type="button" id="shezhi" value="" onclick="shezhi()" />
				<input type="button" id="jieshu" value="" onclick="jieshu()" />
				<input type="button" id="zhanting" value="" onclick="zanTing()" />
				<input type="button" id="kaishi" value="" onclick="kaishi()" />
			</div>
			<div id="lanzi">
			</div>
		</div>
	</body>

</html>